home *** CD-ROM | disk | FTP | other *** search
/ MacFormat 2001 May / macformat_103_may_2001.iso / Mac OS X Shareware / Fizilla / Chrome / embed.jar / content / embed / mini-nav.js < prev    next >
Encoding:
Text File  |  2001-03-26  |  5.4 KB  |  244 lines

  1. /* -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
  2.  *
  3.  * The contents of this file are subject to the Netscape Public
  4.  * License Version 1.1 (the "License"); you may not use this file
  5.  * except in compliance with the License. You may obtain a copy of
  6.  * the License at http://www.mozilla.org/NPL/
  7.  *
  8.  * Software distributed under the License is distributed on an "AS
  9.  * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
  10.  * implied. See the License for the specific language governing
  11.  * rights and limitations under the License.
  12.  *
  13.  * The Original Code is mozilla.org code.
  14.  *
  15.  * The Initial Developer of the Original Code is Netscape
  16.  * Communications Corporation.  Portions created by Netscape are
  17.  * Copyright (C) 1998 Netscape Communications Corporation. All
  18.  * Rights Reserved.
  19.  *
  20.  * Contributor(s): 
  21.  */
  22.  
  23. const nsIWebNavigation = Components.interfaces.nsIWebNavigation;
  24.  
  25. var appCore = null;
  26. var locationFld = null;
  27. var commandHandler = null;
  28. var gURLBar = null;
  29.  
  30. function nsCommandHandler()
  31. {
  32. }
  33.  
  34. nsCommandHandler.prototype = 
  35. {
  36.   QueryInterface : function(iid)
  37.     {
  38.       if (iid.equals(Components.interfaces.nsICommandHandler))
  39.       {
  40.         return this;
  41.       }
  42.       throw Components.results.NS_NOINTERFACE;
  43.     },
  44.  
  45.     exec : function(command, params)
  46.       {
  47.       },
  48.     query : function(command, params, result)
  49.       {
  50.         result = "";
  51.       }
  52. }
  53.  
  54. //
  55.  
  56. function nsXULBrowserWindow()
  57. {
  58. }
  59.  
  60. nsXULBrowserWindow.prototype = 
  61. {
  62.   QueryInterface : function(iid)
  63.     {
  64.     if(iid.equals(Components.interfaces.nsIXULBrowserWindow))
  65.       return this;
  66.     throw Components.results.NS_NOINTERFACE;
  67.     },
  68.   setJSStatus : function(status)
  69.     {
  70.     },
  71.   setJSDefaultStatus : function(status)
  72.     {
  73.     },
  74.   setDefaultStatus : function(status)
  75.     {
  76.     },
  77.   setOverLink : function(link)
  78.     {
  79.     },
  80.   onProgress : function (channel, current, max)
  81.     {
  82.     },
  83.   onStateChange : function (progress, request, state, status)
  84.     {
  85.     },
  86.   onStatus : function(url, message)
  87.     {
  88.     },
  89.   onLocationChange : function(location)
  90.     {
  91.       if(!locationFld)
  92.         locationFld = document.getElementById("urlbar");
  93.  
  94.       // We should probably not do this if the value has changed since the user 
  95.       // searched
  96.       locationFld.setAttribute("value", location);
  97.     }
  98. }
  99.  
  100.  
  101. function MiniNavStartup()
  102. {
  103.   dump("*** MiniNavStartup\n");
  104.   window.XULBrowserWindow = new nsXULBrowserWindow();
  105.  
  106.   var succeeded = false;
  107.   var webNavigation = getWebNavigation();
  108.   try {
  109.     // Create the browser instance component.
  110.     appCore = Components.classes["@mozilla.org/appshell/component/browser/instance;1"]
  111.                         .createInstance(Components.interfaces.nsIBrowserInstance);
  112.  
  113.     webNavigation.sessionHistory = Components.classes["@mozilla.org/browser/shistory;1"]
  114.                                              .createInstance(Components.interfaces.nsISHistory);
  115.     succeeded = true;
  116.   } catch (e) {
  117.   }
  118.  
  119.   if (!succeeded) {
  120.     // Give up.
  121.     dump("Error creating browser instance\n");
  122.     window.close();
  123.   }
  124.   // Initialize browser instance..
  125.   appCore.setWebShellWindow(window);
  126.   _content.appCore = appCore;
  127.  
  128.   // create the embedding command handler
  129.   netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
  130.   var commandHandlerInit = Components
  131.       .classes["@mozilla.org/embedding/browser/nsCommandHandler;1"]
  132.       .createInstance(Components.interfaces.nsICommandHandlerInit);
  133.  
  134.   // Attach it to the window
  135.   commandHandlerInit.window = window;
  136.   commandHandler = commandHandlerInit.QueryInterface(Components.interfaces.nsICommandHandler);
  137.  
  138.   gURLBar = document.getElementById("urlbar");
  139.   dump("gURLBar " + gURLBar + "\n");
  140. }
  141.  
  142. function MiniNavShutdown()
  143. {
  144.   dump("*** MiniNavShutdown\n");
  145.   // Close the app core.
  146.   if ( appCore )
  147.     appCore.close();
  148. }
  149.  
  150. function getBrowser()
  151. {
  152.   return document.getElementById("content");
  153. }
  154.  
  155. function getWebNavigation()
  156. {
  157.   return getBrowser().webNavigation;
  158. }
  159.  
  160. function CHExecTest()
  161. {
  162.   if (commandHandler != null)
  163.   {
  164.     commandHandler.exec("hello", "xxx");
  165.   }
  166. }
  167.  
  168. function CHQueryTest()
  169. {
  170.   if (commandHandler != null)
  171.   {
  172.     var result = commandHandler.query("hello", "xxx");
  173.   }
  174. }
  175.  
  176. function InitContextMenu(xulMenu)
  177. {
  178.   // Back determined by canGoBack broadcaster.
  179.   InitMenuItemAttrFromNode( "context-back", "disabled", "canGoBack" );
  180.  
  181.   // Forward determined by canGoForward broadcaster.
  182.   InitMenuItemAttrFromNode( "context-forward", "disabled", "canGoForward" );
  183. }
  184.  
  185. function InitMenuItemAttrFromNode( item_id, attr, other_id )
  186. {
  187.   var elem = document.getElementById( other_id );
  188.   if ( elem && elem.getAttribute( attr ) == "true" ) {
  189.     SetMenuItemAttr( item_id, attr, "true" );
  190.   } else {
  191.     SetMenuItemAttr( item_id, attr, null );
  192.   }
  193. }
  194.  
  195. function SetMenuItemAttr( id, attr, val )
  196. {
  197.   var elem = document.getElementById( id );
  198.   if ( elem ) {
  199.     if ( val == null ) {
  200.       // null indicates attr should be removed.
  201.       elem.removeAttribute( attr );
  202.     } else {
  203.       // Set attr=val.
  204.       elem.setAttribute( attr, val );
  205.     }
  206.   }
  207. }
  208.  
  209. function loadURI(uri)
  210. {
  211.   getWebNavigation().loadURI(uri, nsIWebNavigation.LOAD_FLAGS_NONE);
  212. }
  213.  
  214. function BrowserLoadURL()
  215. {
  216.   dump("browserloadurl: " + gURLBar.value + '\n');
  217.   try {
  218.     loadURI(gURLBar.value);
  219.   }
  220.   catch(e) {
  221.   }
  222. }
  223.  
  224. function BrowserBack()
  225. {
  226.   getWebNavigation().goBack();
  227. }
  228.  
  229. function BrowserForward()
  230. {
  231.   getWebNavigation().goForward();
  232. }
  233.  
  234. function BrowserStop()
  235. {
  236.   getWebNavigation().stop();
  237. }
  238.  
  239. function BrowserReload()
  240. {
  241.   getWebNavigation().reload(nsIWebNavigation.LOAD_FLAGS_NONE);
  242. }
  243.  
  244.